package at.ac.tuwien.dse.health.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Message addressed to a user of a certain {@link Account}.
 *
 * @author Bernhard Nickel
 * @author Gregor Schauer
 * @author Dominik Strasser
 */
@Entity
@NamedQueries({
		@NamedQuery(name = Message.BY_PATIENT, query = "SELECT m FROM Message m WHERE account.patient = :user AND receiveDate IS NULL"),
		@NamedQuery(name = Message.BY_DOCTOR, query = "SELECT m FROM Message m WHERE account.doctor = :user AND receiveDate IS NULL"),
		@NamedQuery(name = Message.BY_HOSPITAL, query = "SELECT m FROM Message m WHERE account.hospital = :user AND receiveDate IS NULL")
})
public class Message implements Serializable {
	public static final String BY_PATIENT = "Message#byPatient";
	public static final String BY_DOCTOR = "Message#byDoctor";
	public static final String BY_HOSPITAL = "Message#byHospital";
	private Long id;
	private Account account;
	private String title;
	private String message;
	private String type;
	private Date sendDate;
	private Date receiveDate;

	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(optional = false)
	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	@Basic(optional = false)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	@Basic(optional = false)
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@Basic(optional = false)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Basic(optional = false)
	public Date getSendDate() {
		return sendDate;
	}

	public void setSendDate(Date sendDate) {
		this.sendDate = sendDate;
	}

	public Date getReceiveDate() {
		return receiveDate;
	}

	public void setReceiveDate(Date receiveDate) {
		this.receiveDate = receiveDate;
	}

	@Override
	public String toString() {
		return message;
	}
}
